<template>
  <Card style="height:800px">
      <p slot="title" style="color: red;font-size: large;">
        征信任务处理
      </p>
      <marvels-task-count :taskNodes="taskNodes"></marvels-task-count>
      <br>
      <Row>
        <DatePicker type="date" v-model="startCreatedDate" placeholder="进件日期(起)" style="width: 200px"></DatePicker>
        <DatePicker type="date" v-model="endCreatedDate" placeholder="进件日期(止)" style="width: 200px;margin-left: 10px;"></DatePicker>
        <Input v-model="custName" style="width: 200px;margin-left: 15px;" placeholder="客户姓名"></Input>
        <Input v-model="custCardNo" style="width: 200px;margin-left: 15px;" placeholder="身份证号码"></Input>
        <Input v-model="channelName" style="width: 200px;margin-left: 15px;" placeholder="渠道"></Input>
        <Button type="primary" @click="queryPage" style="margin-left: 15px;">查询</Button>
        <Button type="error" @click="getTask" style="margin-left: 15px;">取件</Button>
      </Row>
      <Table stripe border :columns="columns1" :data="data1" style="margin-top: 15px;"></Table>

      <div class="page-box">
        <Page :total="totalNumber" size="small" :current="currentPage" :page-size="pageSize" show-total @on-change="pageIndexChange"></Page>
      </div>
      <Modal v-model="turnOut" title="退单原因"   :mask-closable="false" width="300" :footer-hide="true"  ok-text="保存">
          <Card>
                <p v-for="(item,index) in opinionList" :key="item.loanId">{{index+1 + ':' + item.opinion}}</p>
          </Card>
      </Modal>
  </Card>
</template>
<script>
import marvelsTaskCount from '../../components/marvels-task-count.vue'

export default {
  components: {
    marvelsTaskCount
  },
  data () {
    return {
      $ajax: null,
      taskNodes: ['woCreditInspection'],
      turnOut: false,
      path: this.$route.path,

      totalNumber: 0, // 总记录数

      currentPage: 1, // 当前页码

      pageSize: 20, // 页大小

      startCreatedDate: null,
      endCreatedDate: null,
      channelName: null,
      custCardNo: null,
      channel: null,
      custName: null,
      opinionList: [], // 退单原因
      columns1: [{
        align: 'center',
        type: 'index',
        width: 50,
        title: '序号'
      },
      {
        align: 'center',
        title: '客户姓名',
        key: 'custName',
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('a', {
              style: {
              },
              on: {
                click: function () {
                  // 页面跳转逻辑
                  vm.$router.push({
                    name: 'creditDetailInfo',
                    query: {
                      loanId: params.row.loanId
                    }
                  })
                }
              }
            }, params.row.custName)
          ])
        }
      },
      {
        align: 'center',
        title: '进件号',
        key: 'loanId'
      },
      {
        align: 'center',
        title: '身份证号码',
        key: 'custCardNo'
      },
      {
        align: 'center',
        title: '产品名称',
        key: 'productName'
      },
      {
        align: 'center',
        title: '所属渠道',
        key: 'channelName'
      },
      {
        align: 'center',
        title: '客户经理',
        key: 'employeeName'
      },
      {
        align: 'center',
        title: '业务类型',
        key: 'caseType',
        render: (h, params) => {
          var vm = this
          if (params.row.caseType === 1) {
            return h('div', {}, '补件')
          } else if (params.row.caseStatus === 'ZHAPP' || params.row.caseStatus === 'ZH') {
            return h('div', [
              h('a', {
                style: {
                },
                on: {
                  click: function () {
                    var param = {}
                    param.loanId = params.row.loanId
                    vm.$ajax.post(vm.$appContext.marvels_core_approve + '/approve/process/api/getRefusedReason', param).then(re => {
                      // console.log(param)
                      // console.log(re.data)
                      var code = re.data.code
                      var message = re.data.message
                      if (code !== 'success') {
                        this.$Message.warning(message)
                        return
                      }
                      vm.opinionList = re.data.data
                      vm.turnOut = true
                    }).catch(er => {

                    })
                  }
                }
              }, '新进件')
            ])
          } else {
            return h('div', {}, '新进件')
          }
        }
      },
      {
        align: 'center',
        title: '上报通道',
        key: 'channelName'
      },
      {
        align: 'center',
        title: '进件日期',
        key: 'createdDate',
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('span', vm.$util.formatTime(params.row.createdDate))
          ])
        }
      },
      {
        align: 'center',
        title: '挂起时间',
        key: 'hangTime',
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('span', vm.$util.formatTime(params.row.hangTime))
          ])
        }

      },
      {
        align: 'center',
        title: '挂起原因',
        key: 'hangReason'
      }
      ],
      data1: [

      ]

    }
  },

  methods: {
    pageIndexChange (pageIndex) {
      this.currentPage = pageIndex
      this.queryPage()
    },

    initPage () {
      this.queryPage()
    },

    queryPage () {
      const vm = this
      var params = {
        pageNum: vm.currentPage,
        pageSize: vm.pageSize,
        // curNodeCode:'woCreditInspection',  //页面上写死的
        curNodeCodes: ['woCreditInspection'],
        custCardNo: vm.custCardNo,
        channelName: vm.channelName,
        custName: vm.custName,
        startCreatedDate: vm.startCreatedDate,
        endCreatedDate: vm.endCreatedDate
      }
      vm.$ajax.post(vm.$appContext.marvels_core_approve + '/approve/credit/report/service/list', params).then(re => {
        // console.log(params)
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.data1 = re.data.data.list
        vm.totalNumber = re.data.data.total
      }).catch(er => {

      })
    },

    getTask () {
      const vm = this
      var params = {
        nodeCode: sessionStorage.nodeCode,
        groupCode: sessionStorage.groupCode,
        curNodeCode: 'woCreditInspection' // 页面上写死的
      }
      vm.$ajax.post(vm.$appContext.marvels_core_approve + '/approve/credit/report/service/getTask', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code === 'success') {
          this.$Message.success('取件成功!')
          vm.queryPage()
        } else {
          this.$Message.warning(message)
        }
      }).catch(er => {

      })
    }

  },

  created () {
    // 初始化当前页面请求对象实例
    this.$ajax = this.$util.ajax()
    this.initPage()
  }
}
</script>

<style lang="less">
@import '../../../styles/common.less';
@import '../../../styles/table.less';
</style>
